module approx_softmax #(
  parameter WIDTH = 16,
  parameter LUT_SIZE = 256
)(
  input  wire [WIDTH-1:0]  data_in,
  output wire [WIDTH-1:0]  data_out
);

  // 预计算指数LUT
  reg [WIDTH-1:0] exp_lut[0:LUT_SIZE-1];
  initial begin
    for (int i=0; i<LUT_SIZE; i++) 
      exp_lut[i] = $exp(i/(LUT_SIZE/8.0)) * (2**WIDTH-1);
  end

  // 近似计算流程
  wire [WIDTH/2-1:0] index = data_in[WIDTH-1:WIDTH/2]; // 取高半部分作为索引
  wire [WIDTH-1:0] exp_val = exp_lut[index];
  
  // 动态归一化
  wire [WIDTH*2-1:0] sum_exp;
  always @(posedge clk) begin
    sum_exp <= sum_exp + exp_val;
    data_out <= (exp_val << WIDTH) / sum_exp; 
  end

endmodule